package com.gticket.customerbackend.handler;

import com.gticket.customerbackend.pojo.Statistics;
import com.gticket.customerbackend.pojo.ResponseDate;
import com.gticket.customerbackend.service.StatisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Data
@Api(tags = "统计")
@RequestMapping("/statistics")
public class StatisticsHandler {
    @Autowired
    private StatisticsService statisticsService;

    @GetMapping("/oneDay")
    @ApiOperation(value = "查询指定时间，一日的观影人数和票房.opi")
//    @Cacheable(value = "listPayment",keyGenerator = "myKeyGenerator")
    public ResponseDate listMovies(Statistics statistics){
        ResponseDate responseDate=new ResponseDate();
        try {
            List<Statistics> movies= statisticsService.listStatistics(statistics);
            responseDate.setCode(200);
            responseDate.setMsg("查询成功");
            responseDate.setData(movies);
        }catch (Exception e){
            responseDate.setCode(500);
            responseDate.setMsg("接口异常");
        }
        return responseDate;
    }

    @GetMapping("/times")
    @ApiOperation(value = "查询指定时间段的观影人数和票房")
//    @Cacheable(value = "listPayment",keyGenerator = "myKeyGenerator")
    public ResponseDate listTimes(Statistics statistics){
        ResponseDate responseDate=new ResponseDate();
        try {
            List<Statistics> movies= statisticsService.listTimes(statistics);
            responseDate.setCode(200);
            responseDate.setMsg("查询成功");
            responseDate.setData(movies);
        }catch (Exception e){
            responseDate.setCode(500);
            responseDate.setMsg("接口异常");
        }
        return responseDate;
    }

    @GetMapping("/movies")
    @ApiOperation(value = "查询所有的电影名")
//    @Cacheable(value = "listPayment",keyGenerator = "myKeyGenerator")
    public ResponseDate listAllMovies(Statistics statistics){
        ResponseDate responseDate=new ResponseDate();
        try {
            List<Statistics> movies= statisticsService.listMovies(statistics);
            responseDate.setCode(200);
            responseDate.setMsg("查询成功");
            responseDate.setData(movies);
        }catch (Exception e){
            responseDate.setCode(500);
            responseDate.setMsg("接口异常");
        }
        return responseDate;
    }


}
